]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
st/texture-cache: Split out load_cairo_surface_to_gicon() method
authorFlorian Müllner <fmuellner@gnome.org>
Fri, 12 Mar 2021 23:07:05 +0000 (00:07 +0100)
committerMarge Bot <marge-bot@gnome.org>
Sun, 14 Mar 2021 20:36:41 +0000 (20:36 +0000)
This is essentially st_texture_cache_bind_cairo_surface_property()
without the binding part.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1761>

src/st/st-texture-cache.c
src/st/st-texture-cache.h

index f235ace6ec2239ab1b3275b66a4d1fd864b72cf9..b7b547a782f2a98c058a502e387451bbbe63ecb5 100644 (file)
@@ -742,12 +742,10 @@ typedef struct {
 } StTextureCachePropertyBind;
 
 static void
-st_texture_cache_reset_texture (StTextureCachePropertyBind *bind,
-                                const char                 *propname)
+st_texture_cache_load_surface (ClutterContent  **image,
+                               cairo_surface_t  *surface)
 {
-  cairo_surface_t *surface;
-
-  g_object_get (bind->source, propname, &surface, NULL);
+  g_return_if_fail (image != NULL);
 
   if (surface != NULL &&
       cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_IMAGE &&
@@ -761,10 +759,10 @@ st_texture_cache_reset_texture (StTextureCachePropertyBind *bind,
       height = cairo_image_surface_get_width (surface);
       size = MAX(width, height);
 
-      if (!bind->image)
-        bind->image = st_image_content_new_with_preferred_size (size, size);
+      if (*image == NULL)
+        *image = st_image_content_new_with_preferred_size (size, size);
 
-      clutter_image_set_data (CLUTTER_IMAGE (bind->image),
+      clutter_image_set_data (CLUTTER_IMAGE (*image),
                               cairo_image_surface_get_data (surface),
                               cairo_image_surface_get_format (surface) == CAIRO_FORMAT_ARGB32 ?
                               COGL_PIXEL_FORMAT_BGRA_8888 : COGL_PIXEL_FORMAT_BGR_888,
@@ -776,12 +774,23 @@ st_texture_cache_reset_texture (StTextureCachePropertyBind *bind,
       if (error)
         g_warning ("Failed to allocate texture: %s", error->message);
     }
-  else if (!bind->image)
+  else if (*image == NULL)
     {
-      bind->image = st_image_content_new_with_preferred_size (0, 0);
+      *image = st_image_content_new_with_preferred_size (0, 0);
     }
 }
 
+static void
+st_texture_cache_reset_texture (StTextureCachePropertyBind *bind,
+                                const char                 *propname)
+{
+  cairo_surface_t *surface;
+
+  g_object_get (bind->source, propname, &surface, NULL);
+
+  st_texture_cache_load_surface (&bind->image, surface);
+}
+
 static void
 st_texture_cache_on_pixbuf_notify (GObject           *object,
                                    GParamSpec        *paramspec,
@@ -849,6 +858,25 @@ st_texture_cache_bind_cairo_surface_property (StTextureCache    *cache,
   return G_ICON (bind->image);
 }
 
+/**
+ * st_texture_cache_load_cairo_surface_to_gicon:
+ * @cache: A #StTextureCache
+ * @surface: A #cairo_surface_t
+ *
+ * Create a #GIcon from @surface.
+ *
+ * Returns: (transfer full): A new #GIcon
+ */
+GIcon *
+st_texture_cache_load_cairo_surface_to_gicon (StTextureCache  *cache,
+                                              cairo_surface_t *surface)
+{
+  ClutterContent *image = NULL;
+  st_texture_cache_load_surface (&image, surface);
+
+  return G_ICON (image);
+}
+
 /**
  * st_texture_cache_load: (skip)
  * @cache: A #StTextureCache
index 0e8407ea260c946ed7edefed9c874b014f9fcf48..55d84952d6fe0150ba3bfa5422fc12fb9e02f3c6 100644 (file)
@@ -67,6 +67,9 @@ st_texture_cache_load_sliced_image (StTextureCache *cache,
 GIcon *st_texture_cache_bind_cairo_surface_property (StTextureCache    *cache,
                                                      GObject           *object,
                                                      const char *property_name);
+GIcon *
+st_texture_cache_load_cairo_surface_to_gicon (StTextureCache  *cache,
+                                              cairo_surface_t *surface);
 
 ClutterActor *st_texture_cache_load_gicon (StTextureCache *cache,
                                            StThemeNode    *theme_node,